<extend name="Public/base" />

<block name="body">
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>商品列表</h2>
	</div>
	<div class="cf">
		<div class="fl">
            <a class="btn" href="{:U('add')}">新 增</a>
            <a class="btn" href="{:U('export')}">导 入</a>
            <a class="btn" href="__TEMPLETE__/goods.xlsx">模板下载</a>
            <a class="btn" href="{:U('index', array('sj' => 1))}">上 架</a>
            <a class="btn" href="{:U('index', array('sj' => 0))}">下 架</a>
        </div>

        <div class="search-form fr cf">
        	<div class="sleft">
				<input type="text" name="keyword" class="search-input" value="{:I('keyword')}" placeholder="商品名">
				<a class="sch-btn" href="javascript:;" id="search" url="{:U('index')}"><i class="btn-search"></i></a>
        		<label>分类：</label>
				<select name="class_id" onchange="chooseClass(this);">
					<option value="-1">--请选择--</option>
					<volist name="classes" id="v">
						<option value="{$v.id}" <if condition="I('class_id') eq $v['id']">selected="selected"</if>>{$v.name}</option>
						<volist name="v['_child']" id="v2">
                        	<option value="{$v2.id}" <if condition="$v2['id'] eq $data['class_id']">selected="selected"</if>>&nbsp;&nbsp;├{$v2.name}</option>
                    	</volist>
					</volist>
				</select>
			</div>
		</div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
	<table class="">
    <thead>
        <tr>
		<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
		<th class="">序号</th>
		<th class="">ID</th>
		<th class="">商品名</th>
		<th class="">分类</th>
		<if condition="$data['user_type'] eq 0">
			<th class="">进价</th>
		</if>
		<th class="">点粉价</th>
		<th class="">销量</th>
		<th class="">上架/下架</th>
		<th class=""><a href="{:U('index', array('order' => $paixu))}">是否推荐</a></th>
		<th class="">是否热销</th>
		<th>操作</th>
		</tr>
    </thead>
    <tbody>
		<notempty name="_list">
		<volist name="_list" id="vo">
		<tr>
            <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" /></td>
			<td>{$key + 1} </td>
			<td>{$vo.id}</td>
			<td>{$vo.name}</td>
			<td>{$vo.class_name}</td>
			<if condition="$data['user_type'] eq 0">
			<td>￥{$vo.jj_price}</td>
			</if>
			<td>￥{$vo.price}</td>
			<td>{$vo.sale_count}</td>
			<td><if condition="$vo.is_sj eq 0">下架<else />上架</if></td>
			<td><if condition="$vo.is_recommend eq 0">否<else />是</if></td>
			<td><if condition="$vo.is_hot eq 0">否<else />是</if></td>
			<td>
				<a href="{:U('edit', array('id' => $vo['id']))}">修改</a>
				<a href="{:U('Common/delCommon?table=goods&id='.$vo['id'])}" class="ajax-get confirm">删除</a>
            </td>
		</tr>
		</volist>
		<else/>
		<if condition="$data['user_type'] eq 0">
			<td colspan="12" class="text-center"> aOh! 暂时还没有内容! </td>
		<else />
			<td colspan="11" class="text-center"> aOh! 暂时还没有内容! </td>
		</if>
		</notempty>
	</tbody>
    </table>
	</div>
    <div class="page">
        {$_page}
    </div>
</block>

<block name="script">
	<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

	<script type="text/javascript">
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
	//回车搜索
	$(".search-input").keyup(function(e){
		if(e.keyCode === 13){
			$("#search").click();
			return false;
		}
	});

	function chooseClass(obj){
		var url = "{:U('index')}";
		if( url.indexOf('?')>0 ){
			url += '&class_id=' + obj.value;
		}else{
			url += '?class_id=' + obj.value;
		}
		window.location.href = url;
	}
    //导航高亮
    highlight_subnav('{:U('Goods/index')}');
	</script>
</block>
